var old_best_id=0;
    function checkAnswer(value)
    {
        /*var i,len=0;
        for(i=0;i<value.length;i++)
        {
            len++;
            if(value.charCodeAt(i)>256)
                len++;
        }*/
        if(value.length<5)
        {
            alert("长度不够,您的回复字数不得少于5个！");
        	return false;
        }
        else if(value.length>200)
        {
            alert("字符串长度不得超过200！");
        	return false;
        }
        else
            return true;
    }
    
	function changeAnswerFocus(question_id,is_login){
		if(!is_login)
			document.getElementById(question_id+'_info').style.display="";
		document.getElementById("answerReplyBoxStatic").focus();
	}
	
    function comment_answer(answer_id,question_id,is_login)
    {       
        if(is_login)
        {
        	document.getElementById(answer_id+'_comment').style.display="";
        }
        else
        {
        	document.getElementById(answer_id+'_info').style.display="";
        }
    }

    function comment_dialog(id,display)
    {
        if(display=='yes')
        {
            document.getElementById(id).style.display="";
        }
        else if(display=='no')
        {
            document.getElementById(id).style.display="none";
        }
    }
    

    function vote(vid,type,is_login,answer_id,question_id,user_id)
    {
        if(!is_login)
        {
        	comment_answer(answer_id,question_id,is_login);
        	return false;
        }
    	var url=BASE_HOSTPATH+"/dr-includes/dr-ajax-question-list.php";
    	var xmlhttp=false;
    	if(window.ActiveXObject)
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	else if(window.XMLHttpRequest)
    		xmlhttp=new XMLHttpRequest();
    	if(!xmlhttp)
    	{
    		alert("不能创建XMLHTTP实例");
    		return false;
    	}

    	xmlhttp.open("POST",url,true);
    	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	xmlhttp.onreadystatechange=function()
    	{
    		if(xmlhttp.readyState==4)
    		{
    			var msg=xmlhttp.responseText;
    			if(msg==10)
    				alert('您已经对此投过票了，请24小时后再投票，谢谢');
    			else if(msg==1)
    			{
	    			if(type=="question_up")
	    			{
	    				num=document.getElementById("voteUp-"+vid).innerHTML;
	    				num++;
	    				document.getElementById("voteUp-"+vid).innerHTML=num;
	    			}
	    			else if(type=="question_down")
	    			{
	    				num=document.getElementById("voteDown-"+vid).innerHTML;
	    				num++;
	    				document.getElementById("voteDown-"+vid).innerHTML=num;
	    			}
	    			else if(type=="reply_up")
	    			{
	    				num=document.getElementById("voteUp-answer-"+vid).innerHTML;
	    				num++;
	    				document.getElementById("voteUp-answer-"+vid).innerHTML=num;
	        		}
	    			else if(type=="reply_down")
	    			{
	    				num=document.getElementById("voteDown-answer-"+vid).innerHTML;
	    				num++;
	    				document.getElementById("voteDown-answer-"+vid).innerHTML=num;
	        		}
	    			else if(type=="comment_up")
	    			{
	    				num=document.getElementById("voteUp-comment-"+vid).innerHTML;
	    				num++;
	    				document.getElementById("voteUp-comment-"+vid).innerHTML=num;
	        		}
    			}
    		}
    	}

    	result="vid="+vid+"&type="+type+"&owner_id="+user_id;
    	result+="&nocache="+new Date().getTime();
    	//alert(result);
    	xmlhttp.send(result);
    }

   
    
    function set_best(question_id,answer_id,old_id,value)
    {
        //document.getElementById('best-'+answer_id).value="取消最佳";
        
        var set_type;
        if(value=='设置最佳')
        	set_type='set_best';
        else if(value=='取消最佳')
            set_type='cancel_best';

        
        var url=BASE_HOSTPATH+"/dr-includes/dr-ajax-set-best.php";
    	var xmlhttp=false;
    	if(window.ActiveXObject)
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	else if(window.XMLHttpRequest)
    		xmlhttp=new XMLHttpRequest();
    	if(!xmlhttp)
    	{
    		alert("不能创建XMLHTTP实例");
    		return false;
    	}
        
        xmlhttp.open("POST",url,true);
    	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	xmlhttp.onreadystatechange=function()
    	{
    		if(xmlhttp.readyState==4)
    		{
    			var msg=xmlhttp.responseText;

    			if(msg==1)
    			{
        			
        			if(set_type=='set_best')
        			{
            			if(old_best_id==0)  //第一次，将原有的变成“设置最佳”
            			{
                			var sig1=document.getElementById('best-'+old_id);
                			if(sig1!=null)
                				sig1.value="设置最佳";
            			}
            			else	            //将原来的最佳变成"最佳答案"
            			{
                			var sig2=document.getElementById('best-'+old_best_id);
                			if(sig2!=null)
        						sig2.value="设置最佳";
            			}	
    					
            			
        				document.getElementById('best-'+answer_id).value="取消最佳";
        			}
        			else if(set_type=='cancel_best')
        				document.getElementById('best-'+answer_id).value="设置最佳";
    				
        			old_best_id=answer_id;
        		}
    			else if(msg==0)
    			{}
    			else
        			alert(msg);
    		}
    	}

    	result="qid="+question_id+"&best_id="+answer_id+"&set_type="+set_type;
    	result+="&nocache="+new Date().getTime();
    	//alert(result);
    	xmlhttp.send(result);
		window.location = "/dr-includes/dr-page-question-answer.php?qid=" + question_id;
    }

    
    function mark_question(question_id,is_login,value)
    {
    	
    	if(!is_login)
    	{
    		comment_answer(question_id,question_id,is_login);
    		return false;
    	}
    	var mark_type;
    	if(value=="关注")
    		mark_type='mark';
    	else if(value=="取消关注")
    		mark_type='cancel_mark';
    	var url=BASE_HOSTPATH+"/dr-includes/dr-ajax-mark-question.php";
    	var xmlhttp=false;
    	if(window.ActiveXObject)
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	else if(window.XMLHttpRequest)
    		xmlhttp=new XMLHttpRequest();
    	if(!xmlhttp)
    	{
    		alert("不能创建XMLHTTP实例");
    		return false;
    	}

    	xmlhttp.open("POST",url,true);
    	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	xmlhttp.onreadystatechange=function()
    	{
    		if(xmlhttp.readyState==4)
    		{
    			var msg=xmlhttp.responseText;
    		
    			if(msg==1)
    			{
    				//document.getElementById("mark-"+question_id).disabled=true;
    				if(mark_type=='mark')
    					document.getElementById("mark-"+question_id).value='取消关注';
    				else if(mark_type=='cancel_mark')
    					document.getElementById("mark-"+question_id).value='关注';
    				
    			}
    			else if(msg==0)
    			{
    				//alert(msg);
    			}
    			else
    				alert(msg);
    				
    		}
    	}

    	result="qid="+question_id+"&mark_type="+mark_type;
    	result+="&nocache="+new Date().getTime();
    	xmlhttp.send(result);
    }